<?php

	function article_spider($url){
		//初始化
		$curl = curl_init();
		curl_setopt($curl,CURLOPT_URL,$url);
		curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
		// 总的数据
		$data = array();
		//发送请求
        $str = curl_exec($url);
		/*匹配标题*/
	    $title_pattern = "/<td align=\"center\" class=\"black_20_600\">(.*?)<\/td>/";
		preg_match($title_pattern,$str,$arr);
		$title = $arr[1];
		$data['title'] = $title;

		/*匹配分类*/
		$classify_parttern = "/<a href=\"\.\.\/\" class='cn51black12b CurrChnlCls'>(.*?)<\/a>/";
		preg_match_all($classify_parttern,$str,$arr);
		// $classify = $arr1;
		//print_r($arr);
		 $classify = $arr[1][0];
		$data['classify'] = $classify;

		/*匹配日期*/
		$date_parttern = "/<td align=\"center\" class=\"font03\">(.*?)<\/td>/";
		preg_match_all($date_parttern, $str, $arr);

		$date = $arr[1][0];
		$date = explode("|", $date);
	   $content_parttern = "/<div class=TRS_Editor>(.*?)<\/div>/";
		preg_match_all($content_parttern,$str,$arr);
		// $content = $arr[1][0];
		// $data['content'] = $content;

		//关闭
		curl_close($curl);

		return $data;
	}


	//读取所有数据
	function read_all(){
		/*写入数据，保存文件*/
		file_get_contents('article.json');
		//字符串转换为数组
		$allData = (array)json_decode($json);
		return $allData;
	}

	//追加数据
	function insert($data){
		$allData = read_all();
		//循环,取出数据
		array_push($allData,$data);
		$json = json_encode($allData);
		file_put_contents('article.json',$json);
	}




















